﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApi
{
    public class ApiResponseEntity
    {

        /// <summary>
        /// 响应状态码
        /// </summary>
        public int code { set; get; }
        /// <summary>
        /// 响应信息
        /// </summary>
        public string msg { set; get; }
        /// <summary>
        /// 响应数据
        /// </summary>
        public object data { set; get; }

        public bool isSuccess => this.code == 200;
        /// <summary>
        /// 成功返回200状态码
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResponseEntity Success(string msg, object data)
        {
            this.code = 200;
            this.msg = msg;
            this.data = data;
            return this;
        }

        public ApiResponseEntity Error(string msg, object data)
        {
            this.code = 400;
            this.msg = msg;
            this.data = data;
            return this;
        }

    }
}
